/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.rmi.wizard;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
import org.openide.*;
import org.openide.src.*;
/**
*
* @author Martin Ryzl
*/
public class SelectMethodsPanel extends AbstractWizardPanel {
// ---------------------------------------------------------------------------------------
// WizardPanel initialization
private static boolean DEBUG = false;
static final long serialVersionUID =-2508935221633213685L;
/** Creates new BeanBusinessPanel */
public SelectMethodsPanel() {
initComponents ();
list.setCellRenderer(new ElementListCellRenderer(RMIWizardData.METHOD_HEADER_FORMAT));
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents () {//GEN-BEGIN:initComponents
setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints1;
setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(10, 10, 10, 10)));
setPreferredSize (new java.awt.Dimension(480, 320));
titleLabel = new javax.swing.JLabel ();
titleLabel.setText ("Select Methods");
titleLabel.setFont (new java.awt.Font ("Dialog", 0, 18));
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridy = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints1.insets = new java.awt.Insets (2, 2, 10, 2);
gridBagConstraints1.weightx = 1.0;
add (titleLabel, gridBagConstraints1);
contentPanel = new javax.swing.JPanel ();
contentPanel.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints2;
listScroll = new javax.swing.JScrollPane ();
list = new javax.swing.JList ();
listScroll.setViewportView (list);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridwidth = 0;
gridBagConstraints2.gridheight = 0;
gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints2.weightx = 1.0;
gridBagConstraints2.weighty = 1.0;
contentPanel.add (listScroll, gridBagConstraints2);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridy = 1;
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints1.weightx = 1.0;
gridBagConstraints1.weighty = 1.0;
add (contentPanel, gridBagConstraints1);
protectedButton = new javax.swing.JToggleButton ();
protectedButton.setIcon (new javax.swing.ImageIcon (getClass ().getResource ("/org/netbeans/modules/rmi/resources/protected.gif")));
protectedButton.setToolTipText ("Protected");
protectedButton.setMargin (new java.awt.Insets(1, 1, 1, 1));
protectedButton.addItemListener (new java.awt.event.ItemListener () {
public void itemStateChanged (java.awt.event.ItemEvent evt) {
protectedButtonItemStateChanged (evt);
}
}
);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridx = 3;
gridBagConstraints1.gridy = 0;
gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
add (protectedButton, gridBagConstraints1);
packageButton = new javax.swing.JToggleButton ();
packageButton.setIcon (new javax.swing.ImageIcon (getClass ().getResource ("/org/netbeans/modules/rmi/resources/package.gif")));
packageButton.setToolTipText ("Package");
packageButton.setMargin (new java.awt.Insets(1, 1, 1, 1));
packageButton.addItemListener (new java.awt.event.ItemListener () {
public void itemStateChanged (java.awt.event.ItemEvent evt) {
packageButtonItemStateChanged (evt);
}
}
);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridx = 2;
gridBagConstraints1.gridy = 0;
add (packageButton, gridBagConstraints1);
publicButton = new javax.swing.JToggleButton ();
publicButton.setIcon (new javax.swing.ImageIcon (getClass ().getResource ("/org/netbeans/modules/rmi/resources/public.gif")));
publicButton.setToolTipText ("Public");
publicButton.setMargin (new java.awt.Insets(1, 1, 1, 1));
publicButton.setSelected (true);
publicButton.addItemListener (new java.awt.event.ItemListener () {
public void itemStateChanged (java.awt.event.ItemEvent evt) {
publicButtonItemStateChanged (evt);
}
}
);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridx = 1;
gridBagConstraints1.gridy = 0;
add (publicButton, gridBagConstraints1);
}//GEN-END:initComponents
private void publicButtonItemStateChanged (java.awt.event.ItemEvent evt) {//GEN-FIRST:event_publicButtonItemStateChanged
// Add your handling code here:
// toggle filter for public methods
setData();
}//GEN-LAST:event_publicButtonItemStateChanged
private void protectedButtonItemStateChanged (java.awt.event.ItemEvent evt) {//GEN-FIRST:event_protectedButtonItemStateChanged
// Add your handling code here:
// toggle filter for protected methods
setData();
}//GEN-LAST:event_protectedButtonItemStateChanged
private void packageButtonItemStateChanged (java.awt.event.ItemEvent evt) {//GEN-FIRST:event_packageButtonItemStateChanged
// Add your handling code here:
// toggle filter for package private methods
setData();
}//GEN-LAST:event_packageButtonItemStateChanged
private void removeButtonPressed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonPressed
}//GEN-LAST:event_removeButtonPressed
private void addButtonPressed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonPressed
}//GEN-LAST:event_addButtonPressed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel titleLabel;
private javax.swing.JPanel contentPanel;
private javax.swing.JScrollPane listScroll;
private javax.swing.JList list;
private javax.swing.JToggleButton protectedButton;
private javax.swing.JToggleButton packageButton;
private javax.swing.JToggleButton publicButton;
// End of variables declaration//GEN-END:variables
ClassElement celement;
protected void setData() {
try {
MethodElement[] mes = (MethodElement[])celement.getMethods();
Vector methods = new Vector(32);
int mod;
// apply filter
// filter out private methods, the rest by the buttons
for(int i = 0; i < mes.length; i++) {
mod = mes[i].getModifiers();
// it must not be private
if (Modifier.isPrivate(mod)) continue;
// if the method is public and it is enabled -> ok
if (Modifier.isPublic(mod)) {
if (publicButton.isSelected()) methods.add(mes[i]);
continue;
}
// if the method is protected and it is enabled -> ok
if (Modifier.isProtected(mod)) {
if (protectedButton.isSelected()) methods.add(mes[i]);
continue;
}
if (packageButton.isSelected()) methods.add(mes[i]);
}
list.setListData(methods);
list.revalidate();
} catch (NullPointerException ex) {
// nothing can be done
}
}
// ---------------------------------------------------------------------------------------
// WizardDescriptor.Panel implementation
public void storeRMISettings(RMIWizardData data) {
// save selected methods
Object[] objs = list.getSelectedValues();
int len = objs.length;
// create right array
MethodElement[] methods = new MethodElement[len];
System.arraycopy(objs, 0, methods, 0, len);
// create copy of methods
try {
ClassElement fake = new ClassElement();
fake.addMethods(methods);
methods = fake.getMethods();
} catch (SourceException ex) {
// ignore it
}
for(int i = 0; i < len; i++) {
try {
SrcSupport.addException(methods[i], SrcSupport.REMOTE_EXCEPTION);
SrcSupport.nameParameters(methods[i].getParameters());
} catch (SourceException ex) {
// ignore it
}
}
data.methods = methods;
celement = null;
}
public void readRMISettings(RMIWizardData data) {
ClassElement ce = data.source.getClass(Identifier.create(data.sourceName));
if (DEBUG) System.err.println("SelectMethodsPanel: ce = " + ce + ", name = " + data.sourceName);
celement = ce;
setData();
}
}
/*
* <<Log>>
* 9 Gandalf 1.8 11/27/99 Patrik Knakal
* 8 Gandalf 1.7 10/23/99 Ian Formanek NO SEMANTIC CHANGE - Sun
* Microsystems Copyright in File Comment
* 7 Gandalf 1.6 8/16/99 Martin Ryzl method filter in RMI
* Encapsulation Wizard service URL in RMIDataObject
* 6 Gandalf 1.5 8/16/99 Martin Ryzl debug prints were
* removed
* 5 Gandalf 1.4 7/28/99 Martin Ryzl added selection of
* executor
* 4 Gandalf 1.3 7/28/99 Martin Ryzl
* 3 Gandalf 1.2 7/27/99 Martin Ryzl first steps to the
* encapsulation
* 2 Gandalf 1.1 7/27/99 Martin Ryzl new version of generator
* is working
* 1 Gandalf 1.0 7/27/99 Martin Ryzl
* $
*/